package ua.com.infinite.mobile.slidingmenu;

import ua.com.infinite.mobile.R;
import ua.com.infinite.mobile.adapters.PageAdapter;
import ua.com.infinite.mobile.pageindicator.TitlePageIndicator;
import ua.com.infinite.mobile.slidingmenu.lib.SlidingMenu;
import ua.com.infinite.mobile.slidingmenu.lib.app.SlidingFragmentActivity;
import android.annotation.SuppressLint;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;

public class BaseSlidingActivity extends SlidingFragmentActivity {
	private int titleRes;

	/*
	 * protected PageAdapter mAdapter; protected ViewPager mPager; protected
	 * TitlePageIndicator mIndicator;
	 */

	// protected ListFragment baseMenuFragment;
	protected BaseMenuFragment baseMenuFragment;

	public BaseSlidingActivity(int titleRes) {
		this.titleRes = titleRes;
	}

	@SuppressLint("NewApi")
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setTitle(titleRes);

		setContentView(R.layout.content_frame);

		setBehindContentView(R.layout.menu_frame);

		SlidingMenu sm = getSlidingMenu();

		sm.setShadowWidthRes(R.dimen.shadow_width);
		sm.setShadowDrawable(R.drawable.shadow);
		sm.setBehindOffsetRes(R.dimen.actionbar_home_width);

		FragmentTransaction fragmTransaction = this.getSupportFragmentManager().beginTransaction();
		if (savedInstanceState != null) {
			baseMenuFragment = (BaseMenuFragment) getSupportFragmentManager().getFragment(savedInstanceState, "menu");
		} else {
			baseMenuFragment = new BaseMenuFragment();
		}
		fragmTransaction.replace(R.id.menu_frame, baseMenuFragment);
		fragmTransaction.commit();
		
		// customize the ActionBar
		if (Build.VERSION.SDK_INT >= 11) {
			getActionBar().setDisplayHomeAsUpEnabled(true);
		}

	}

	@Override
	public void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
		getSupportFragmentManager().putFragment(outState, "menu", baseMenuFragment);

	}

	public BaseMenuFragment getBaseMenuFragment() {
		return (BaseMenuFragment) this.baseMenuFragment;
	}

}
